$(function(){
    
    layui.use("layer", function(){
        var layer = layui.layer;
    })

    function get_unlock_img_func(){
        $.ajax({
            url: app_root + "get_unlock_img",
            type: "get",
            dataType: "json",
            headers: {
                "X-CSRFToken": get_csrf_token(),
            },
        }).done(function(msg){
            console.log(msg)
            if(msg.code==200){
                var data = "data:image/png;base64,"+msg.data
                $("#login_verify_img").attr("src", data)
            }
        }).fail(function(e){
            console.log(e)
        })
    }
    get_unlock_img_func()


    $("#submit").click(function(){
        var verify_input = $("#verify_img_input").val()
        $.ajax({
            url: app_root + "unlock_ip",
            type: "post",
            dataType: "json",
            data:{
                verify_img_input: verify_input,
            },
            headers: {
                "X-CSRFToken": get_csrf_token(),
            },
        }).done(function(msg){
            if(msg.code==200){
                layer.msg(msg.msg)
                window.location.href = app_root + 'index';
            }else{
                layer.msg(msg.msg)
            }
        }).fail(function(e){
            console.log(e)
        })
    })
})